package com.panshi.controller;

import com.panshi.service.IFunctionService;
import com.panshi.vo.FunctionVO;
import com.panshi.vo.KeyValueVO;
import com.panshi.vo.ResultVO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping(path = "rule")
public class FunctionController {

    @Autowired
    private IFunctionService iFunctionService;

     // 初始化菜单功能首页数据
    //@RequiresPermissions("rule:list")
    @RequestMapping("/view/functionList")
    @ResponseBody
    public ResultVO<List<FunctionVO>> findFuncList(){
        return iFunctionService.findFuncList();
    }

    // 根据id查询指定的查单功能首页数据
    @GetMapping("/view/{id}")
    public ResultVO<FunctionVO> getFunInfo(@PathVariable long id){
        return iFunctionService.getFunInfo(id);
    }

    // 更改状态
    @PutMapping("/edit/status")
    @ResponseBody
    public ResultVO<String> updateFunStatus(@RequestBody  FunctionVO functionVO){
        return  iFunctionService.updateFunStatus(functionVO.getId(),functionVO.getStatus());
    }

    // 增加一个菜单功能
    //@RequiresPermissions("rule:add")
    @PostMapping("/add")
    @ResponseBody
    public ResultVO<String> addFunInfo(@RequestBody FunctionVO functionVO){
        return iFunctionService.addFunInfo(functionVO);
    }

    // 删除菜单功能信息
    //@RequiresPermissions("rule:del")
    @DeleteMapping("/del/{id}")
    @ResponseBody
    public ResultVO<String> delFunInfo(@PathVariable long id){
        return iFunctionService.delFunInfo(id);
    }

    // 更改菜单功能信息
    //@RequiresPermissions("rule:edit")
    @PutMapping("/edit")
    @ResponseBody
    public ResultVO<String> editFunInfo(@RequestBody FunctionVO functionVO){
        return iFunctionService.editFunInfo(functionVO);
    }

    // 初始化角色新增时的菜单功能选项
    @GetMapping("/view/initFunList")
    @ResponseBody
    public ResultVO<List<KeyValueVO>> initFunList(){
        return iFunctionService.initFunList();
    }

    // 查询 修改角色信息时当前角色拥有的权限
    @GetMapping("/view/getRoleSelect/{roleId}")
    @ResponseBody
    public ResultVO<List<KeyValueVO>> getRoleSelect(@PathVariable long roleId){
        return iFunctionService.getRoleSelect(roleId);
    }

}
